package com.avit.tv.kui;

import android.content.Context;
import android.text.TextUtils;
import android.util.AttributeSet;

/**
 * 设定好的跑马灯textview
 * 适合于子控件使用，控制跑马灯开始和结束，但是缺少速度和纵向控制
 * @author like
 * @date 2020/6/29
 */
public class AvitPartChildMarqueeView extends androidx.appcompat.widget.AppCompatTextView implements Cloneable {

    private boolean isFocused = false;

    public AvitPartChildMarqueeView(Context context) {
        this(context,null);
    }

    public AvitPartChildMarqueeView(Context context, AttributeSet attrs) {
        this(context, attrs,0);
    }

    public AvitPartChildMarqueeView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        setMarqueeRepeatLimit(Integer.MAX_VALUE);
        setEllipsize(TextUtils.TruncateAt.MARQUEE);
        setSingleLine(true);
    }

    @Override
    public boolean isFocused() {
        return isFocused || super.isFocused();
    }

    public void setFocused(boolean focused) {
        isFocused = focused;
    }

    public void makeFocusable(boolean isFocusable){
        setFocusable(isFocusable);
        setFocusableInTouchMode(isFocusable);
    }

    @Override
    public AvitPartChildMarqueeView clone() {
        AvitPartChildMarqueeView cloneView  = null;
        try {
            cloneView  = (AvitPartChildMarqueeView) super.clone();
        }catch (Exception e){
            e.printStackTrace();
        }
        return cloneView;
    }
}
